/*
 * Copyright (C) 2024-2025 Deepin Technology Co., Ltd.
 *
 * Author:     zhangbingyi <zhangbingyi@uniontech.com>
 *
 * Maintainer: zhangbingyi <zhangbingyi@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "pwdlevelchangeddlg.h"

#include <QPushButton>
#include <QLabel>

#include <QScrollArea>

PwdLevelChangedDlg::PwdLevelChangedDlg(QWidget *parent)
    : DDialog(parent)
{
    this->setAccessibleName("pwdLevelDialog");
//    setWindowFlag(Qt::WindowStaysOnTopHint);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setModal(true);
    setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
    setIcon(QIcon::fromTheme(DIALOG_TIP_YELLOW));
    setFixedWidth(380);
    clearContents(); //清除文本
    clearButtons(); //清除按钮

    QLabel *txt = new QLabel(tr("Your password policy is higher, please change your password to meet the requirements"), this);
    txt->setAccessibleName("pwdLevelDialog_tipLable");
    txt->setWordWrap(true); //设置换行
    txt->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
    txt->setMinimumHeight(30);
    // 添加滑动区域
    QScrollArea *scrollArea = new QScrollArea(this);
    scrollArea->setFrameShape(QFrame::Shape::NoFrame);
    scrollArea->setWidgetResizable(true);
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
    scrollArea->setFixedHeight(50);
    QPalette pa = scrollArea->palette();
    pa.setColor(QPalette::ColorRole::Background, Qt::transparent);
    scrollArea->setPalette(pa);
    scrollArea->setWidget(txt);
    addContent(scrollArea);

    // 针对DTK弹窗目前accessibleName会随系统语言变化的情况
    // 通过insertButton的形式定制按钮,保持accessiableName的一致性
    QPushButton *okBtn = new QPushButton(this);
    okBtn->setText(tr("OK", "button"));
    okBtn->setObjectName("okBtn");
    okBtn->setAccessibleName("pwdLevelDialog_okBtn");
    okBtn->setAttribute(Qt::WA_NoMousePropagation);
    this->insertButton(0, okBtn, false);
}

PwdLevelChangedDlg::~PwdLevelChangedDlg()
{
}

